package org.example.Interfaces.facade;

import org.example.Interfaces.dto.UserQueryDto;
import org.example.domain.user.entity.User;
import org.example.domain.user.service.UserService;
import org.example.controller.BaseController;
import org.example.model.ApiResponse;
import org.example.model.PageInfo;
import org.example.util.ApiResponseUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user")
public class UserController extends BaseController<User, UserService> {
    public UserController(@Autowired UserService service) {
        super(service);
    }

    /**
     * 按名字查询
     * @param name
     * @return
     */
    @RequestMapping("/list/name")
    public ApiResponse<List<User>> listByName(@RequestParam("name") String name) {
        List<User> list= service.listByName(name);
        return ApiResponseUtil.success(list);
    }

    /**
     * 使用 userQueryDto对象 查询用户
     * @param userQueryDto
     * @return
     */
    @PostMapping("/query")
    public ApiResponse<List<User>> queryUsers(@RequestBody UserQueryDto userQueryDto) {
        List<User> list= service.queryUsers(userQueryDto);
        return ApiResponseUtil.success(list);
    }


    @PostMapping("/query/page")
    public ApiResponse<PageInfo<User>> queryUserPage(@RequestBody UserQueryDto userQueryDto) {
        PageInfo<User> userPage= service.queryUserPage(userQueryDto);
        return ApiResponseUtil.success(userPage);
    }

}
